﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyVoteMVC.BackstageManagement.Views;
using MyVoteMVC.Service;
using MyVoteMVC.Common;

namespace MyVoteMVC.BackstageManagement.Controllers
{
    public interface IMessageController
    {
        void GetActivityList();
        void GetMessageList(string activityID);
        void DeleteMessage(string activityID, string messageID);
        void FindMessage(string strContent);
    }


    public class MessageController : IMessageController
    {

        IMessageService messageService;
        IActivityService activityService;
        IMessageManagementView view;
        public MessageController(IMessageManagementView view)
        {
            this.view = view;
            messageService = Factory.GetInstance<IMessageService>();
            activityService = Factory.GetInstance<IActivityService>();
        }

        public void GetActivityList()
        {
            view.GetActivityListComplete(activityService.GetActivities());
        }

        public void GetMessageList(string activityID)
        {
            view.GetMessageListComplete(messageService.GetMessageList(activityID));
        }

        public void DeleteMessage(string activityID, string messageID)
        {
            if (string.IsNullOrEmpty(activityID) || string.IsNullOrEmpty(messageID))
            {
                view.DeleteMessageComplete("没有可以删除的信息！");
            }
            else
            {
                messageService.DeleteMessage(activityID, messageID);
                view.DeleteMessageComplete("删除完成！");
            }
        }

        public void FindMessage(string strContent)
        {
            if (string.IsNullOrEmpty(strContent))
            {
                view.FindMessageComplete(null);
            }
            else
            {
                view.FindMessageComplete(messageService.FindMessageList(strContent));
            }
        }
    }
}
